﻿using System;
using System.Data;
using Common;

namespace iPortal.Control
{
    public partial class ctrLeafMenu : System.Web.UI.UserControl
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindMenu();
            }
        }
        protected void BindMenu()
        {
            string strFomatProduct = " AND categoryId=346 OR categoryId=356";
            string sql = string.Format("exec tblCategory_GetAllByCondition '{0}'", strFomatProduct);
            var dsParentMenu = DAL.GetDataSet(sql);

            if (dsParentMenu != null && dsParentMenu.Tables[0].Rows.Count > 0)
            {
                lblHTML.Text += "<ul><li>";
                foreach (DataRow dr in dsParentMenu.Tables[0].Rows)
                {
                    //<a href=Default.aspx?CateId=31D96F0FCAEA-" + dr["categoryId"] + ">"</a>
                    lblHTML.Text += "<h2>" + dr["categoryName"] + "</h2>";
                                     
                    string sql2 = string.Format("exec tblCategory_GetAllByCondition '{0}'", " AND parentId= " + dr["categoryId"]);
                    var dsChildMenu = DAL.GetDataSet(sql2);
                    if (dsChildMenu != null && dsChildMenu.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow dr2 in dsChildMenu.Tables[0].Rows)
                        {
                            lblHTML.Text += "<ul><li><a href=Default.aspx?CateId=" + dr2["categoryId"].ToString() +">" + dr2["categoryName"] + "</a></li></ul>";
                        }
                    }

                }
                lblHTML.Text += "</li></ul>";
            }

        }
    }
}

